<template>
  <view class="docMainInfo">
    <view class="myNavFlexd">
      <view class="myNav">
        <AtNavBar
          :onClickLeftIcon="goBackClick"
          color="#000"
          :title="myTitle"
          leftIconType="chevron-left"
        />
        <view class="save" @tap="savePage" v-if="role === 'student'">保存</view>
      </view>
    </view>
    <view class="mySteps">
      <scroll-view :scrollX="true">
        <AtSteps
          :items="items"
          :current="currentPage-1"
        />
      </scroll-view>
    </view>

    <scroll-view :scrollY="true" style="height: 20rem;">

    <AtForm v-show="currentPage ===1">
      <AtInput
        :disabled="lock || !roleLock"
        name="dept_name"
        title="实习科室:"
        type="text"
        placeholder="请输入实习科室"
        :value="mainInfo.dept_name"
        :onChange="handleChange.bind(this,'dept_name')"
      />
      <view class="dateItem">
        <picker
          :disabled="lock || !roleLock"
          mode="date"
          v-model="mainInfo.start_date"
        >
          <view class="demo-list-item">
            <view class="demo-list-item__label">开始日期:</view>
            <view class="demo-list-item__value">{{ mainInfo.start_date }}</view>
          </view>
        </picker>
      </view>
      <view class="dateItem">
        <picker
          :disabled="lock || !roleLock"
          mode="date"
          v-model="mainInfo.end_date"
        >
          <view class="demo-list-item">
            <view class="demo-list-item__label">结束日期:</view>
            <view class="demo-list-item__value">{{ mainInfo.end_date }}</view>
          </view>
        </picker>
      </view>
      <AtInput
        :disabled="lock || !roleLock"
        name="stu_name"
        title="实习生姓名:"
        type="text"
        placeholder="请输入实习生姓名"
        :value="mainInfo.stu_name"
        :onChange="handleChange.bind(this,'stu_name')"
      />
      <AtInput
        :disabled="lock || !roleLock"
        name="stu_num"
        title="实习生学号:"
        type="text"
        placeholder="请输入实习生学号"
        :value="mainInfo.stu_num"
        :onChange="handleChange.bind(this,'stu_num')"
      />
    </AtForm>

    <AtForm v-show="currentPage === 2">
      <view style="font-weight: bold;">（一）实习项目基本情况一览表</view>
      <view>
        <view>
          <table border="1" width="100%" cellpadding="0" cellspacing="0" align="center" style="font-size: 16px">
            <caption style="font-size: 20px;font-weight: bold;">
              学习项目一览表
            </caption>
            <thead>
            <tr>
              <th width="25%">学习项目</th>
              <th width="45%">题目</th>
              <th width="20%">参与形式</th>
              <th width="10%">/</th>
            </tr>
            </thead>
            <tbody align="center">
            <tr v-for="(item,index) in mypageArr.learn_data">
              <td width="25%">{{ item.learn_item }}</td>
              <td width="45%">{{ item.title }}</td>
              <td width="20%">{{ item.method }}</td>
              <td width="10%">
                <AtIcon v-if="role === 'student'" value="close-circle" size="30" color="#f00"
                        :on-click="delItem.bind(this,'learn_data',index)"
                ></AtIcon>
              </td>
            </tr>
            </tbody>
            <tfoot align="center">
            <tr>
              <td width="25%">
                <AtInput
                  :disabled="lock || !roleLock"
                  name="learn_item"
                  type="text"
                  placeholder="学习项目"
                  :value="myPage2Item.learnItem.learn_item"
                  :onChange="handleItemChange.bind(this,'learnItem','learn_item')"
                  style="margin: 0;width: 100%;"
                />
              </td>
              <td width="45%">
                <AtInput
                  :disabled="lock || !roleLock"
                  name="title"
                  type="text"
                  placeholder="题目"
                  :value="myPage2Item.learnItem.title"
                  :onChange="handleItemChange.bind(this,'learnItem','title')"
                  style="margin: 0"
                />
              </td>
              <td width="20%">
                <picker
                  class="demo-list-item__value"
                  mode="selector"
                  :range="learn_item_method"
                  :value="myPage2Item.learnItem.method"
                  @change="handlePikerChange"
                  @cancel="handlePikerCancel"
                  style="margin: 0"
                >
                  {{ myPage2Item.learnItem.method }}
                </picker>
              </td>
              <td width="10%">
                <AtIcon v-if="role === 'student'" value="add-circle" size="30" color="#6190E8"
                        :on-click="addArrItem.bind(this,'learn_data','learnItem')"
                        style="margin: 0"
                ></AtIcon>
              </td>
            </tr>
            </tfoot>
          </table>
        </view>

        <view>
          <table border="1" width="100%" cellpadding="0" cellspacing="0" align="center" style="font-size: 16px">
            <caption style="font-size: 20px;font-weight: bold;">
              操作项目一览表
            </caption>
            <thead>
            <tr>
              <th width="50%">操作项目</th>
              <th width="25%">操作次数</th>
              <th width="25%">/</th>
            </tr>
            </thead>
            <tbody align="center">
            <tr v-for="(item,index) in mypageArr.operate_data">
              <td width="50%">{{ item.operate_item }}</td>
              <td width="25%">{{ item.num }}</td>
              <td width="25%">
                <AtIcon v-if="role === 'student'" class="tag" value="close-circle" size="30" color="#f00"
                        :on-click="delItem.bind(this,'operate_data',index)"
                ></AtIcon>
              </td>
            </tr>
            </tbody>
            <tfoot align="center">
            <tr>
              <td width="50%">
                <AtInput
                  class="input1"
                  :disabled="lock || !roleLock"
                  name="operate_item"
                  type="text"
                  placeholder="操作项目"
                  :value="myPage2Item.operateItem.operate_item"
                  :onChange="handleItemChange.bind(this,'operateItem','operate_item')"
                  style="margin:0;width: 100%;"
                />
              </td>
              <td width="25%">
                <AtInputNumber
                  :disabled="lock || !roleLock"
                  :min="1"
                  :step="1"
                  :value="myPage2Item.operateItem.num"
                  :onChange="handleItemChange.bind(this,'operateItem','num')"
                  style="margin:0;"
                />
              </td>
              <td width="25%">
                <AtIcon v-if="role === 'student'" class="tag" value="add-circle" size="30" color="#6190E8"
                        :on-click="addArrItem.bind(this,'operate_data','operateItem')"
                ></AtIcon>
              </td>
            </tr>
            </tfoot>
          </table>
        </view>
      </view>

      <view class="disease">
        <view style="font-weight: bold;">（二）实习病种（至少4个）</view>
        <table border="1" width="100%" cellpadding="0" cellspacing="0" align="center" style="font-size: 16px">
          <thead>
          <tr>
            <th width="20%">序号</th>
            <th width="55%">实习病种</th>
            <th width="25%">/</th>
          </tr>
          </thead>
          <tbody align="center">
          <tr v-for="(item,index) in mypageArr.disease_data">
            <td width="20%">{{ index + 1 }}</td>
            <td width="55%">{{ item }}</td>
            <td width="25%">
              <AtIcon v-if="role === 'student'" class="tag" value="close-circle" size="30" color="#f00"
                      :on-click="delItem.bind(this,'disease_data',index)"
              ></AtIcon>
            </td>
          </tr>
          </tbody>
          <tfoot align="center">
          <tr>
            <td width="20%">
              {{ diseaseIndex }}
            </td>
            <td width="55%">
              <AtInput
                :disabled="lock || !roleLock"
                name="arrItem"
                type="text"
                placeholder="请输入实习病种"
                :value="myPage2Item.diseaseItem"
                :onChange="handleItemChange.bind(this,'diseaseItem','diseaseItem')"
              />
            </td>
            <td width="25%">
              <AtIcon v-if="role === 'student'" class="tag" value="add-circle" size="30" color="#6190E8"
                      :on-click="addArrItem.bind(this,'disease_data','diseaseItem')"
              ></AtIcon>
            </td>
          </tr>
          </tfoot>
        </table>
      </view>
    </AtForm>

    <AtForm v-show="currentPage === 3">
      <view class="myTextarea">
        <view class="XS"
        >
          自我鉴定:
        </view>
        <AtTextarea
          :count="false"
          :disabled="lock || !roleLock"
          class="mytextarea"
          name="summary"
          :value="mainInfo.summary"
          :onChange="handleChange.bind(this,'summary')"
          :maxLength="10000"
          placeholder="请输入自我鉴定"
        />
      </view>
      <AtButton type="primary" size="small" :onClick="submitDoc" v-if="role === 'student'">提交</AtButton>

    </AtForm>

    <AtForm v-show="currentPage === 4">
      <view class="attendance">
        <view class="item">
          <view>病假:</view>
          <AtInput
            :disabled="lock || roleLock"
            name="F"
            type="number"
            :value="myPage4.attendance.F"
            :onChange="handleItemChange.bind(this,'attendance','F')"
          />
          <view>天</view>
        </view>
        <view class="item">
          <view>事假:</view>
          <AtInput
            :disabled="lock || roleLock"
            name="E"
            type="number"
            :value="myPage4.attendance.E"
            :onChange="handleItemChange.bind(this,'attendance','E')"
          />
          <view>天</view>
        </view>
        <view class="item">
          <view>旷工:</view>
          <AtInput
            :disabled="lock || roleLock"
            name="J"
            type="number"
            :value="myPage4.attendance.J"
            :onChange="handleItemChange.bind(this,'attendance','J')"
          />
          <view>天</view>
        </view>
      </view>
      <view>
        <AtInput
          :disabled="lock || roleLock"
          name="t_name"
          title="带教老师姓名:"
          type="text"
          placeholder="请输入带教老师姓名"
          :value="myPage4.t_name"
          :onChange="handleChange.bind(this,'t_name')"
        />
        <AtInput
          :disabled="lock || roleLock"
          name="t_title"
          title="带教老师职称:"
          type="text"
          placeholder="请输入带教老师职称"
          :value="myPage4.t_title"
          :onChange="handleChange.bind(this,'t_title')"
        />
      </view>
      <view class="myTextarea">
        <view class="XS"
        >
          带教评语:
        </view>
        <AtTextarea
          :disabled="lock || roleLock"
          class="mytextarea"
          name="remark"
          :value="mainInfo.remark"
          :onChange="handleChange.bind(this,'remark')"
          :maxLength="800"
          placeholder="带教评语"
        />
      </view>
      <view class="results">
        <table border="1" width="100%" cellpadding="0" cellspacing="0" align="center" style="font-size: 16px">
          <caption style="font-size: 20px;font-weight: bold;">
            出科成绩评定
          </caption>
          <thead>
          <tr>
            <th width="35%">考核项目</th>
            <th width="20%">满分</th>
            <th width="45%">得分</th>
          </tr>
          </thead>
          <tbody align="center">
          <tr>
            <td width="35%">素质考核</td>
            <td width="20%">30分</td>
            <td width="45%"><AtInput
              class="itemIput"
              :disabled="lock || roleLock"
              name="QA"
              type="number"
              :value="myPage4.results.QA"
              :onChange="handleItemChange.bind(this,'results','QA')"
            /></td>
          </tr>
          <tr>
            <td width="35%">理论考核</td>
            <td width="20%">30分</td>
            <td width="45%"><AtInput
              class="itemIput"
              :disabled="lock || roleLock"
              name="TA"
              type="number"
              :value="myPage4.results.TA"
              :onChange="handleItemChange.bind(this,'results','TA')"
            /></td>
          </tr>
          <tr>
            <td width="35%">技能考核</td>
            <td width="20%">40分</td>
            <td width="45%"><AtInput
              class="itemIput"
              :disabled="lock || roleLock"
              name="SA"
              type="number"
              :value="myPage4.results.SA"
              :onChange="handleItemChange.bind(this,'results','SA')"
            /></td>
          </tr>
          </tbody>
          <tfoot align="center">
          <tr>
            <td width="35%">
              /
            </td>
            <td width="20%">
              总分
            </td>
            <td width="45%">
              <AtInput
                class="totalInput"
                :disabled="lock || roleLock"
                name="total"
                type="number"
                :value="myPage4.results.total"
                :onChange="handleItemChange.bind(this,'results','total')"
              />
            </td>
          </tr>
          </tfoot>
        </table>
      </view>

    </AtForm>

    <AtForm v-show="currentPage === 5">
      <AtInput
        :disabled="lock || roleLock"
        name="t_name"
        title="护士长姓名:"
        type="text"
        placeholder="请输入护士长姓名"
        :value="mainInfo.t_name"
        :onChange="handleChange.bind(this,'t_name')"
      />
      <view class="myTextarea">
        <view class="XS">
          护士长意见:
        </view>
        <AtTextarea
          :disabled="lock || roleLock"
          class="mytextarea"
          name="remark"
          :value="mainInfo.remark"
          :onChange="handleChange.bind(this,'remark')"
          :maxLength="800"
          placeholder="护士长意见"
        />
      </view>
      <view class="myImage">
        <view class="XSimg"
        >
          护士长工作证:
        </view>
        <view class="img">
          <AtImagePicker
            :showAddBtn="imglock"
            :files="files"
            count="1"
            :onChange="onChange"
          />
        </view>
      </view>
    </AtForm>

    <view v-if="page === 4">
      <Sign title="带教老师签名" :role="lock || roleLock" @getSignUrl="getSignUrl"></Sign>
      <AtButton class="deptBtn" type="primary" size="small" :onClick="submitDocDept" v-if="role === 'dept'">提交
      </AtButton>
    </view>
    <view v-if="page === 5">
      <Sign title="护士长签名" :role="lock || roleLock" @getSignUrl="getSignUrl"></Sign>
      <AtButton class="deptBtn" type="primary" size="small" :onClick="submitDocDept" v-if="role === 'dept'">提交
      </AtButton>
    </view>

    </scroll-view>
    <view class="myPages">
      <AtPagination
        :total="5"
        :pageSize="1"
        :current="currentPage1"
        :onPageChange="onPageChange"
      >
      </AtPagination>
    </view>
    <AtMessage/>

  </view>
</template>

<script>
import './index.scss'
import Taro from "@tarojs/taro";
import Sign from "../../components/Sign";

export default {
  components: {Sign},
  data() {
    return {
      roleLock: false,
      myPage4: {
        attendance: {
          F: 0,
          E: 0,
          J: 0
        },
        t_name: '',
        t_title: '',
        remark: '',
        results: {
          QA: 0,
          TA: 0,
          SA: 0,
          total: 0
        },
        t_sign: '',
        t_photo: ''
      },
      mypageArr: {
        learn_data: [],
        operate_data: [],
        disease_data: [],
      },
      learn_item_method: ['主讲', '参与'],
      myPage2Item: {
        learnItem: {
          learn_item: "",
          title: "",
          method: "主讲"
        },
        operateItem: {
          operate_item: "",
          num: 1,
        },
        diseaseItem: "",
      },
      role: '',
      token: "",
      files: [],
      myTitle: "",
      uploadUrl: "http://npis.mocoder.cn/?s=App.Doc_Student.Upload",
      imgUploadUrl: "http://npis.mocoder.cn/?s=App.Doc_Unit.Upload",
      pdfUrl: "",
      imageUrl: "",
      lock: false,
      items: [
        {title: "基本信息",},
        {title: "实习基本情况",},
        {title: "自我鉴定",},
        {title: "带教审核",},
        {title: "护士长审核",},
      ],
      currentPage: 1,
      currentPage1: 1,
      mod_id: "",
      doc_id: "",
      page: 1,
      mainInfo: {}
    }
  },
  computed: {
    learnIndex() {
      return this.mypageArr.learn_data.length + 1 + ''
    },
    operateIndex() {
      return this.mypageArr.operate_data.length + 1 + ''
    },
    diseaseIndex() {
      return this.mypageArr.disease_data.length + 1 + ''
    },
    imglock() {
      if (this.lock) {
        return false
      }
      return !this.roleLock;
    }
  },
  created() {
    this.currentPage = Taro.getStorageSync("itemDocInfo").current_page;
    this.currentPage1 = Taro.getStorageSync("itemDocInfo").current_page;
    this.page = Taro.getStorageSync("itemDocInfo").current_page;

  },
  mounted() {
    this.doc_id = this.$taro.Current.router.params.doc_id;
    this.mod_id = this.$taro.Current.router.params.mod_id;
    this.myTitle = Taro.getStorageSync("itemDocInfo").title;
    this.token = Taro.getStorageSync("token")
    this.role = Taro.getStorageSync("userInfo").role;
    if (this.role === "student") {
      this.roleLock = true
    }
    if (this.role === 'student') {
      this.getDocStudent()
    } else {
      this.getDocDept()
    }
  },
  methods: {
    getSignUrl(e) {
      // console.log(e)
      let ImgObj = this.dataURLtoFile(e, 'img.png');
      let signImgUrl = this.getObjectURL(ImgObj);
      // console.log(ImgObj)
      // console.log(this.getObjectURL(ImgObj))
      console.log(signImgUrl)
      Taro.uploadFile({
        url: this.imgUploadUrl,
        filePath: signImgUrl,
        header: {
          'Authorization': this.token
        },
        name: 'file',//修改上传文件的名称
        fileName: "file.png",
      }).then((res, rej) => {
        console.log(res, rej)
        let tempData = JSON.parse(res.data)
        if (tempData.ret === 200) {
          this.mainInfo.t_sign = tempData.data.url
          Taro.atMessage({
            message: '上传签名成功',
            type: 'success'
          })
        } else {
          Taro.atMessage({
            message: '上传签名失败',
            type: 'warning'
          })
        }
      })
    },
    // 获取上传图片文件的真实路径
    getObjectURL(file) {
      var url = null;
      if (window.createObjcectURL !== undefined) {
        url = window.createOjcectURL(file);
      } else if (window.URL !== undefined) {
        url = window.URL.createObjectURL(file);
      } else if (window.webkitURL !== undefined) {
        url = window.webkitURL.createObjectURL(file);
      }
      return url;
    },
    // 将base64转换为文件
    dataURLtoFile(dataurl, filename) {
      var arr = dataurl.split(',');
      var mime = arr[0].match(/:(.*?);/)[1];
      var bytes = window.atob(arr[1]);            // 去掉url的头，并转化为byte
      //let n = new ArrayBuffer(bytes.length);    // 处理异常,将ascii码小于0的转换为大于0
      var n = bytes.length,
        u8arr = new Uint8Array(n);                  // 生成视图（直接针对内存）：8位无符号整数，长度1个字节
      while (n--) {
        u8arr[n] = bytes.charCodeAt(n);
      }
      return new File([u8arr], filename, {type: mime});
    },
    delItem(name, index) {
      this.mypageArr[name].splice(index, 1)
    },
    handleItemChange(name1, name2, val) {
      if (this.page === 4) {
        if (name1 === 'attendance' || 'results') {
          let tempVal = Number(val)
          this.myPage4[name1][name2] = tempVal
          // console.log(tempVal)
          // console.log(this.myPage4[name1][name2])
        } else {
          this.myPage4[name1][name2] = val
        }
      } else if (name2 === 'num') {
        if (val === 0) {
          this.myPage2Item[name1][name2] = this.myPage2Item[name1][name2];

        } else {
          this.myPage2Item[name1][name2] = Number(val);
        }

      } else if (name1 === 'diseaseItem') {
        // console.log(3)

        this.myPage2Item[name1] = val
      } else {
        // console.log(4)

        this.myPage2Item[name1][name2] = val;
      }
    },
    addArrItem(name1, name2) {
      if (name1 === 'disease_data') {
        this.mypageArr[name1].push(this.myPage2Item[name2]);
        this.myPage2Item[name2] = "";
      } else {
        let myPage2Item = this.deepClone(this.myPage2Item[name2]);
        this.mypageArr[name1] = [...this.mypageArr[name1], myPage2Item];
        if(name1 === 'learn_data'){
          this.myPage2Item[name2] = {
            learn_item: "",
            title: "",
            method: "主讲"
          };
        }else if (name1 === 'operate_data'){
          this.myPage2Item[name2] = {
            operate_item: "",
              num: 1,
          };
        }
      }
      // console.log(name1, name2);
      // console.log(this.mypageArr[name1])
    },
    handlePikerChange(e) {
      this.myPage2Item.learnItem.method = this.learn_item_method[e.detail.value];
      // console.log(e)
      // console.log(this.myPage2Item.learnItem.method)
    },
    handlePikerCancel(){
      //do nothing
    },
    /**
     * 深克隆解决radio
     */
    deepClone(data) {
      if (!data || !(data instanceof Object) || (typeof data == "function")) {
        return data || undefined;
      }
      var constructor = data.constructor;
      var result = new constructor();
      for (var key in data) {
        if (data.hasOwnProperty(key)) {
          result[key] = this.deepClone(data[key]);
        }
      }
      return result;
    },
    submitDocDept() {
      this.submitDeptDoc();
    },
    submitDoc(e) {
      this.submitStuDoc();
    },
    onChange(files) {
      // console.log('chacha20')
      // console.log(files)
      if (files.length === 1) {
        //   files.splice(0,1);
        // console.log(files)
        this.files = files
        Taro.uploadFile({
          url: this.imgUploadUrl,
          filePath: files[0].file.path,
          header: {
            'Authorization': this.token
          },
          name: 'file',//修改上传文件的名称
          fileName: "file.png",
        }).then((res, rej) => {
          console.log(res, rej)
          let tempData = JSON.parse(res.data)
          console.log(tempData)
          if (this.page === 4) {
            this.myPage4.t_photo = tempData.data.url;
          } else {
            this.mainInfo.t_photo = tempData.data.url
          }
          // console.log(this.myPage4)
          this.mainInfo.t_sign = 'http://npis.mocoder.cn/?s=App.Doc_Student.Upload'
          console.log(this.mainInfo)
        })
      }

      if (files.length > 1) {
        files.splice(0, files.length - 1);
        this.files = files
      } else {
        this.files = files
      }
    },
    addFile(e) {
      console.log(e)
      if (e.target.children[0].files.length !== 0) {
        let resource = URL.createObjectURL(e.target.children[0].files[0])
        console.log(resource)
        Taro.uploadFile({
          url: this.uploadUrl,
          filePath: resource,
          name: "file",
          fileName: 'file.pdf',
          header: {
            "Authorization": this.token
          }
        }).then((res, rej) => {
          console.log(res, rej)
          let data = JSON.parse(res.data)
          if (rej) {
            Taro.showToast({
              title: "文件上传失败",
              icon: "none"
            })
          }
          if (data.ret === 200) {
            this.pdfUrl = data.data.url;
            this.mainInfo.file = this.pdfUrl;
            console.log(this.pdfUrl)
          } else {
            Taro.showToast({
              title: "文件上传失败",
              icon: "none"
            })
          }
        })
      }
    },
    savePage() {
      if (this.page === 2) {
        console.log(this.mypageArr)
        this.mainInfo = this.mypageArr;
      }
      if (this.page === 4) {
        this.mainInfo.nursing_diagnosis = this.mylist;
      }
      console.log(this.mainInfo);
      // console.log(JSON.stringify(this.mainInfo))
      this.updateDoc();
    },
    goBackClick() {
      Taro.navigateBack({
        delta: 1
      })
    },
    onPageChange(val) {
      // console.log(val)
      this.currentPage = val.current
      this.page = this.currentPage;
      // console.log(this.currentPage,this.$el.children[1].children[0])
      //调整步骤条位置
      const scroll_position = [0, 0, 30, 170, 305, 340];
      this.$el.children[1].children[0].scrollLeft = scroll_position[this.currentPage];
      if (this.role === 'student') {
        this.getDocStudent()
      } else {
        this.getDocDept()
      }
      // console.log(this.currentPage)
    },
    handleChange(name, val) {
      if (this.page === 4) {
        this.myPage4[name] = val;
      }
      if (name === "arrItem") {
        this.arrItem = val
      } else {
        this.mainInfo[name] = val;
      }
    },
    getDate() {
      let D = new Date();
      let year = D.getFullYear();
      let m = D.getMonth() + 1;
      if (m < 10) {
        m = '0' + m;
      }
      let d = D.getDate();
      if (d < 10) {
        d = '0' + d;
      }
      // console.log(year + '-' + m + '-' + d);
      return year + '-' + m + '-' + d
    },
    /**
     * 获取文档数据
     * @returns {Promise<void>}
     */
    async getDocStudent() {
      let res = await this.$myRequest({
        url: "?s=App.Doc_Student.GetDoc",
        data: {
          doc_id: this.doc_id,
          page: this.page
        }
      })
      // console.log(res)
      if (this.page === 4) {
        this.myPage4 = res.data.data.content;
      }
      if (res.data.data.content.disease_data) {
        this.mypageArr.disease_data = res.data.data.content.disease_data;
        this.mypageArr.learn_data = res.data.data.content.learn_data;
        this.mypageArr.operate_data = res.data.data.content.operate_data;
      }
      this.mainInfo = res.data.data.content;
      if (!this.mainInfo.start_date) {
        this.mainInfo.start_date = this.getDate();
      }
      if (!this.mainInfo.end_date) {
        this.mainInfo.end_date = this.getDate();
      }
      // console.log(this.mainInfo)
      if (res.data.data.locked === 1) {
        this.lock = true;
      }
    },
    /**
     * 获取文档数据
     * @returns {Promise<void>}
     */
    async getDocDept() {
      let res = await this.$myRequest({
        url: "?s=App.Doc_Unit.GetDoc",
        data: {
          doc_id: this.doc_id,
          page: this.page
        }
      })
      console.log(res)
      if (res.data.data.content.nursing_diagnosis) {
        this.mylist = res.data.data.content.nursing_diagnosis;
        console.log(this.mylist)
      }
      this.mainInfo = res.data.data.content;
      if (res.data.data.locked === 1) {
        console.log(res.data.data.locked)
        this.lock = true;
      } else {
        this.lock = false;
      }
      console.log(this.lock)
    },
    /**
     *  更新文档数据
     * @returns {Promise<void>}
     */
    async updateDoc() {
      console.log(this.mainInfo)
      let res = await this.$myRequest({
        url: "?s=App.Doc_Student.Update",
        data: {
          doc_id: this.doc_id,
          content: JSON.stringify(this.mainInfo),
          page: this.page
        }
      })
      console.log(res)
      if (res.data.ret === 200) {
        Taro.atMessage({
          message: '保存成功',
          type: "success"
        })
      }
    },
    /**
     * 提交文档审核
     * @returns {Promise<void>}
     */
    async submitStuDoc() {
      let res = await this.$myRequest({
        url: "?s=App.Doc_Student.Submit",
        data: {
          doc_id: this.doc_id,
        }
      })
      console.log(res)
      if (res.data.ret === 200) {
        Taro.atMessage({
          message: "提交审核成功",
          type: "success"
        })
      }
    },
    /**
     * 带教提交文档审核
     * @returns {Promise<void>}
     */
    async submitDeptDoc() {
      let content
      if (this.page === 4) {
        content = JSON.stringify(this.myPage4)
      } else {
        content = JSON.stringify(this.mainInfo)
      }
      let res = await this.$myRequest({
        url: "?s=App.Doc_Unit.Submit",
        data: {
          doc_id: this.doc_id,
          content: content,
          page: this.page
        }
      })
      console.log(res)
      if (res.data.ret === 200) {
        this.files = []
        if (this.page === 4) {
          this.myPage4 = {}
        }
        this.mainInfo = {}
        Taro.atMessage({
          message: "提交审核成功",
          type: "success"
        })
        await this.getDocDept()

      }
    },
  },
}
</script>

<style lang="less">
.deptBtn {
  margin-top: 1rem;
}

.disease {
  .myList {
    .item {
      margin-top: 1rem;
    }
  }

  .listTitle {
    display: flex;
    align-items: center;
    font-size: 0.8rem;
    line-height: 1.5;
    vertical-align: middle;
    text-align: left;
    color: #333;

    .index {
      margin-left: 0.5rem
    }

    .type {

    }
  }
}

.results {
  .nav {
    display: flex;
    font-size: 0.8rem;
    line-height: 1.5;
    vertical-align: middle;
    text-align: left;
    color: #333;

    .navItem {
      width: 7.3rem;
      margin-left: 1.55rem;
    }
  }

  .list {
    .totalItem {
      font-size: 0.8rem;
      line-height: 1.5;
      vertical-align: middle;
      text-align: left;
      color: #333;
      display: flex;
      align-items: center;

      .totalTitle {
        width: 6rem;
        margin-left: 1.5rem;
      }

      .totalInput {
        width: 1rem;
        margin-left: 0;

        .at-input__input {
          padding-right: 0;
        }
      }
    }

    .item {
      font-size: 0.8rem;
      line-height: 1.5;
      vertical-align: middle;
      text-align: left;
      color: #333;
      display: flex;
      justify-content: center;
      align-items: center;
      margin-left: 1.55rem;

      .title {
        width: 6rem;
        margin-right: 1.5rem;

      }

      .itemIput {
        margin-left: 4rem;
        width: 5rem;
      }

      .score {
        width: 3.5rem;
      }
    }
  }
}

.attendance {
  display: flex;

  .item {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 7.3rem;
    font-size: 0.8rem;
    line-height: 1.5;
    vertical-align: middle;
    text-align: left;
    color: #333;

    .at-input {
      margin-left: 0.6rem;
      width: 40px;
    }

    .at-input__input {
      padding-right: 0;
    }
  }
}

.myInput {
  margin-top: 0.5rem;
  display: flex;
  justify-content: center;
  align-items: center;

  .at-input__title {
    margin-right: 0;
    width: 2.8rem;
  }
}

.listTitle {
  display: flex;
  align-items: flex-start;
  width: 100%;
  font-size: 0.8rem;
  line-height: 1.5;
  vertical-align: middle;
  text-align: left;
  margin-left: 0.75rem;
  color: #333;

  .index {
    margin-right: 1.25rem;
  }
}

.listBtn {
  margin-top: 0.5rem;
}

.myList {
  .item {
    margin-top: 1.5rem;
    position: relative;
    display: flex;
    align-items: flex-start;
    width: 100%;
    font-size: 0.8rem;
    line-height: 1.5;
    vertical-align: middle;
    text-align: left;
    margin-left: 1rem;
    color: #333;
    flex: 1;

    .index {
      margin-right: 2.3rem;
      margin-left: 0.5rem;
    }

    .tag {
      position: absolute;
      right: 1.8rem;
    }
  }
}

.at-steps {
  width: 700PX;
}

.myImage {
  display: flex;
  flex-direction: column;
  padding-left: 0.4rem;

  .XSimg {
    width: 7.3rem;
    font-size: 0.8rem;
    line-height: 1.5;
    vertical-align: middle;
    text-align: left;
    margin-left: 0.45rem;
    color: #333;
  }

  .img {
    margin-left: 0.7rem;
  }
}

.uploadPdf {
  display: flex;
  flex-direction: column;
  padding: 0px 1.5rem 0px 1.3rem;

  .weui-input {
    height: 2rem;
    margin-top: 9px;
  }

  .title {
    margin-right: 0.4rem;
    width: 7.3rem;
    font-size: 0.8rem;
    line-height: 1.5;
    vertical-align: middle;
    text-align: left;
    color: #333;
  }

  .tips {
    width: 100%;
    font-size: 0.75rem;
    line-height: 1.5;
    vertical-align: middle;
    text-align: left;
    color: #333;
  }
}

.myTextarea {
  .XS {
    margin-right: 0.4rem;
    width: 7.3rem;
    font-size: 0.8rem;
    line-height: 1.5;
    vertical-align: middle;
    text-align: left;
    margin-left: 0.75rem;
    color: #333;
  }

  .mytextarea {
    width: 80%;
    margin-left: 1.675rem;
    margin-top: 0.4rem;
  }
}

.docMainInfo {
  margin-bottom: 1.5rem;
}

.mySteps {
  margin-top: 3rem;
}

.myPages {
  position: fixed;
  width: 100%;
  bottom: 0;
  background-color: #FFFFFF;
}

.myNavFlexd {
  position: fixed;
  top: 0;
  width: 100%;
  background-color: #FFFFFF;
  z-index: 10;

  .myNav {
    margin-bottom: 20px;
    position: relative;

    .save {
      position: absolute;
      top: 0.39rem;
      right: 0.5rem;
      color: #333;
      font-size: 18PX;
    }
  }
}

.dateItem {
  display: flex;

  .demo-list-item__label, .demo-list-item__value {
    font-size: 0.8rem;
    line-height: 1.5;
    margin-right: 1rem;
    margin-left: 0.3rem;
  }
}

.XS {
  margin-right: 0.4rem;
  width: 7.3rem;
  font-size: 0.8rem;
  line-height: 1.5;
  vertical-align: middle;
  text-align: left;
  margin-left: 0.75rem;
  color: #333;
}

.theme {
  .at-input__title {
    width: 5.8rem;
  }
}

.at-input__title {
  width: 5.3rem;
}
</style>
